package com.gdust.gkyx.product.controller;

import com.gdust.gkyx.common.result.Result;
import com.gdust.gkyx.model.product.Attr;
import com.gdust.gkyx.product.service.AttrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: AttrController
 * Package: com.gdust.gkyx.product.controller
 * Description:商品属性 前端控制器
 *
 * 参考前端src >api>product > attr.js进行接口编写
 *
 * @Author syun
 * @Create 2025/1/25 9:21
 * @Version 1.0
 */
@Api(tags = "商品属性")
@RestController
@RequestMapping("/admin/product/attr")
//@CrossOrigin
public class AttrController {
    //注入商品属性表的service
    @Autowired
    private AttrService attrService;

    /**
     * //平台属性列表方法
     *     //根据平台属性分组id查询
     * //    url: `${api_name}/${groupId}`,
     * //    method: 'get'
     * @param groupId 属性分组id
     * @return
     */
    @ApiOperation("根据平台属性分组id查询")
    @GetMapping("{groupId}")
    public Result list(@PathVariable Long groupId) {
        List<Attr> list = attrService.getAttrListByGroupId(groupId);
        return Result.ok(list);
    }

    /**
     * 获取
     * @param id 属性id
     * @return
     */
    @ApiOperation(value = "获取")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        Attr attr = attrService.getById(id);
        return Result.ok(attr);
    }

    /**
     * 新增
     * @param attr
     * @return 属性对象
     */
    @ApiOperation(value = "新增")
    @PostMapping("save")
    public Result save(@RequestBody Attr attr) {
        attrService.save(attr);
        return Result.ok(null);
    }

    /**
     * 修改
     * @param attr 属性对象
     * @return
     */
    @ApiOperation(value = "修改")
    @PutMapping("update")
    public Result updateById(@RequestBody Attr attr) {
        attrService.updateById(attr);
        return Result.ok(null);
    }

    /**
     *删除
     * @param id 属性id
     * @return
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        attrService.removeById(id);
        return Result.ok(null);
    }

    /**
     *根据id列表删除
     * @param idList 属性id集合
     * @return
     */
    @ApiOperation(value = "根据id列表删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        attrService.removeByIds(idList);
        return Result.ok(null);
    }



}
